<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>商城|注册</title>
		<meta content="商城" name="author">
		<meta content="商城" name="Copyright">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<meta content="商城" name="description">
		<meta content="商城" name="keywords">
		<!--<link rel="stylesheet" type="text/css" href="css/public.css">-->
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<link rel="stylesheet" type="text/css" href="__INDEX__/css/register.css">
		<link rel="shortcut icon" href="__INDEX__/images/favorite.ico">
		<script src="__INDEX__/js/jquery-1.9.1.min.js"></script>
	</head>

	<body>
		<div class="g-wrap">
			<div class="g-header">
				<a href="{:url('Index/index')}" class="logo"><img src="{$logo}" /></a>
				<div class="r"><img src="images/sprite-hash-91639fdc.png"></div>
			</div>
			<div class="g-content" style="background: url(__INDEX__/images/loginBg.jpg) no-repeat;height: 600px;">
				<div class="login">
					<div class="form-top-tip">
						<span id="J_head_tip">欢迎注册</span>
						<a class="" href="{:url('Login/index')}">已有账号，登录</a>
					</div>
					<div class="form">
						<form method="post">
							<div class="group">
								<label for="name">用户名</label>
								<input class="name" name="account" id="name" placeholder="用户名" />
							</div>
							<div class="group">
								<label for="tel">手机号</label>
								<input class="tel" name="phone" id="phone" placeholder="手机号" />
							</div>
							<div class="group">
								<label for="check">验证码</label>
								<input class="check" name="verify_code" id="check" placeholder="验证码" />
								<input type="button" id="btn_s" class="checkbtn" value="获取验证码" />
							</div>
							<div class="group">
								<label for="passwd">密码</label>
								<input type="password" name="pwd" class="passwd" id="passwd" placeholder="密码" />
							</div>
							<div class="group">
								<label for="repassword">确认密码</label>
								<input type="password" name="pwd_new" class="repassword" id="repassword" placeholder="确认密码" />
							</div>
							<input type="hidden" id="pid" value="{$Arr.pid}">
							<input type="submit" id="submit" class="submit" value="注册" />
						</form>
					</div>
				</div>
			</div>
		</div>
	    <script src="__INDEX__/js/layer/mobile/layer_mobile.js"></script>
	    <script src="__INDEX__/js/layer/mobile/layer.js"></script>
	    <script src="__INDEX__/js/common.js"></script>
		<script>
        $("#submit").click(function(){

            var account = $("input[name='account']").val();
            var pwd = $("input[name='pwd']").val();
            var pwd_new = $("input[name='pwd_new']").val();
            var phone = $("input[name='phone']").val();
           	var verify_code = $("input[name='verify_code']").val();
            var pid = $("#pid").val();
            var pwz = $("#pwz").val();
            if(account.match(/^[a-zA-Z0-9_]{5,11}$/)==null){
                prompt_From_one("请输入账号");
                return false;
            }

            if(phone.match(/^1[34578]\d{9}$/) == null){
                prompt_From_one("请输入正确手机号码格式");
                return false;
            }

            if(pwd.match(/^[a-zA-Z0-9]{6,10}$/)==null){
                prompt_From_one("请输入密码");
                return false;
            }

            if(pwd_new.match(/^[a-zA-Z0-9]{6,10}$/)==null || pwd!=pwd_new){
                prompt_From_one("两次密码不一致");
                return false;
            }

            

           	if(verify_code.match(/^\d{6}$/) == null){
              	prompt_From_one("请输入正确的验证码");
               	return false;
           	}

            $.ajax({
                type: 'POST',
                url: '{:url("Register/register")}',
                dataType: 'json',
                data: {account: account,pwd: pwd,phone: phone,
              		verify_code: verify_code,pid:pid,
                },

                success: function (data) {
                    if( data.result == 0 ){
                        layer.open({
                            content: data.msg
                            ,style: 'color:#ffffff;border:none;'
                            ,time: 2 //2秒后自动关闭
                            ,end:function(){
                                location.href = '{:url("Index/index")}';
                            }
                        });
                    }else{
                        prompt_From_one(data.msg);
                    }
                }
            });
            return false;
        });


	</script>

		<script>

			$("#btn_s").click(function(){
		    var timer=null,num=60;
		    var phone= $('#phone').val();

		    if ("" == phone || !phone) {
	            prompt_From_one("请输入手机号!");
		        return false;
		    } else {
		        var reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
		        //验证规则
		        if (!reg.test(phone)) {
	                prompt_From_one("手机号格式错误!");
		            return false;
		        }
		    }
		    $.ajax({
		        type: 'POST',
		        url: '{:url("Register/reg_code")}',
		        dataType: 'json',
		        data: {phone: phone},
		        success: function (data) {
		            if( data.result == 0 ){
	                    prompt_From_one(data.msg);
		            }else{
	                    prompt_From_one(data.msg);
		            }
		        }
	    	});

		    timer = setInterval(function(){

			    $(".checkbtn").attr("disabled",true);
			    $(".checkbtn").val(num+"s"+"重新发送");
			    if(num < 0){
			        $(".checkbtn").val("获取验证码 ");
			        $(".checkbtn").removeAttr("disabled");
			        clearInterval(timer);
			    }
			    num--;
			},1000);

		})
		</script>
	</body>

</html>